﻿/*
 * This class provides an example of using contracts on an interface 
 * All classes that implement the interface will inherit the contracts 
 * Refer to the code contracts documentation for more information
 */
using System;
using System.Diagnostics.Contracts;
using System.Linq;

namespace Shweet.Repository
{
    [ContractClass(typeof(IShweetMessagesContract))]
    public interface IShweetMessages 
    {
        void Add(Shweet shweet);
        Shweet [] Load(string [] tags);
        Shweet[] Load(string[] tags, string shweetTeamSiteUrl);
    }

    [ContractClassFor(typeof(IShweetMessages))]
    sealed class IShweetMessagesContract  : IShweetMessages
    {        
        void IShweetMessages.Add(Shweet shweet)
        {
            Contract.Requires(shweet != null);
            Contract.Requires(shweet.IsValid());
        }

        Shweet[] IShweetMessages.Load(string[] tags)
        {
            Contract.Requires(tags != null);
            Contract.Requires(tags.All(tag => (tag != null)));
            Contract.Ensures(Contract.Result<Shweet[]>() != null);
            
            return null;  //To make csharp happy
        }

        Shweet[] IShweetMessages.Load(string[] tags, string shweetTeamSiteUrl)
        {
            Contract.Requires(tags != null);
            Contract.Requires(tags.All(tag => (tag != null)));
            return null;
        }
    }
}


